package MOLE;

import java.util.*;

/** 
 ҳ������У����
 ����ƽ
 2004.8
*/
public class PageValidate
{
	private static Regex RegNumber = new Regex("^[0-9]+$");
	private static Regex RegNumberSign = new Regex("^[+-]?[0-9]+$");
	private static Regex RegDecimal = new Regex("^[0-9]+[.]?[0-9]+$");
	private static Regex RegDecimalSign = new Regex("^[+-]?[0-9]+[.]?[0-9]+$"); //�ȼ���^[+-]?\d+[.]?\d+$
	private static Regex RegEmail = new Regex("^[\\w-]+@[\\w-]+\\.(com|net|org|edu|mil|tv|biz|info|cn)$"); //w Ӣ����ĸ�����ֵ��ַ������� [a-zA-Z0-9] �﷨һ��
	private static Regex RegCHZN = new Regex("[\u4e00-\u9fa5]");

	public PageValidate()
	{
	}


//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#region �����ַ������

	/** 
	 ���Request��ѯ�ַ����ļ�ֵ���Ƿ������֣���󳤶�����
	 
	 @param req Request
	 @param inputKey Request�ļ�ֵ
	 @param maxLen ��󳤶�
	 @return ����Request��ѯ�ַ���
	*/
	public static String FetchInputDigit(HttpRequest req, String inputKey, int maxLen)
	{
		String retVal = "";
		if (inputKey != null && !inputKey.equals(""))
		{
			retVal = req.QueryString[inputKey];
			if (retVal.equals(null))
			{
				retVal = req.Form[inputKey];
			}
			if (!retVal.equals(null))
			{
				retVal = SqlText(retVal, maxLen);
				if (!IsNumber(retVal))
				{
					retVal = "";
				}
			}
		}
		if (retVal == null)
		{
			retVal = "";
		}
		return retVal;
	}
	/** 
	 �Ƿ������ַ���
	 
	 @param inputData �����ַ���
	 @return 
	*/
	public static boolean IsNumber(String inputData)
	{
		Match m = RegNumber.Match(inputData);
		return m.Success;
	}
	/** 
	 �Ƿ������ַ��� �ɴ�������
	 
	 @param inputData �����ַ���
	 @return 
	*/
	public static boolean IsNumberSign(String inputData)
	{
		Match m = RegNumberSign.Match(inputData);
		return m.Success;
	}
	/** 
	 �Ƿ��Ǹ�����
	 
	 @param inputData �����ַ���
	 @return 
	*/
	public static boolean IsDecimal(String inputData)
	{
		Match m = RegDecimal.Match(inputData);
		return m.Success;
	}
	/** 
	 �Ƿ��Ǹ����� �ɴ�������
	 
	 @param inputData �����ַ���
	 @return 
	*/
	public static boolean IsDecimalSign(String inputData)
	{
		Match m = RegDecimalSign.Match(inputData);
		return m.Success;
	}

//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#endregion

//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#region ���ļ��

	/** 
	 ����Ƿ��������ַ�
	 
	 @param inputData
	 @return 
	*/
	public static boolean IsHasCHZN(String inputData)
	{
		Match m = RegCHZN.Match(inputData);
		return m.Success;
	}

//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#endregion

//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#region �ʼ���ַ
	/** 
	 �Ƿ��Ǹ����� �ɴ�������
	 
	 @param inputData �����ַ���
	 @return 
	*/
	public static boolean IsEmail(String inputData)
	{
		inputData = inputData.toLowerCase();
		Match m = RegEmail.Match(inputData);
		return m.Success;
	}

//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#endregion

//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#region ����

	/** 
	 ����ַ�����󳤶ȣ�����ָ�����ȵĴ�
	 
	 @param sqlInput �����ַ���
	 @param maxLength ��󳤶�
	 @return 			
	*/
	public static String SqlText(String sqlInput, int maxLength)
	{
		if (sqlInput != null && !sqlInput.equals(""))
		{
			sqlInput = sqlInput.trim();
			if (sqlInput.length() > maxLength) //����󳤶Ƚ�ȡ�ַ���
			{
				sqlInput = sqlInput.substring(0, maxLength);
			}
		}
		return sqlInput;
	}


	/** 
	 �ַ�������
	 
	 @param inputData
	 @return 
	*/
	public static String HtmlEncode(String inputData)
	{
		return HttpUtility.HtmlEncode(inputData);
	}
	/** 
	 ����Label��ʾEncode���ַ���
	 
	 @param lbl
	 @param txtInput
	*/
	public static void SetLabel(Label lbl, String txtInput)
	{
		lbl.Text = HtmlEncode(txtInput);
	}
	public static void SetLabel(Label lbl, Object inputObj)
	{
		SetLabel(lbl, inputObj.toString());
	}

//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#endregion

	public static boolean IsInt(ArrayList a)
	{

		for (int i = 0;i < a.size();i++)
		{
			String s = a.get(i).toString();
			if (!IsInt(s))
			{
				return false;
			}
		}
		return true;


	}

	//�Ƿ��Ǵ���0������
	public static boolean IsInt(String s)
	{
		try
		{
			double d = Double.parseDouble(s);
			long i = java.lang.Math.round(d);


			if ((double)i == d && i > 0)
			{
				return true;
			}
			else
			{
				return false;
			}

		}
		catch (java.lang.Exception e)
		{
			return false;

		}

	}
}